import 'package:flutter/material.dart';
import 'package:flutter_oa/product/product.dart';
import 'package:flutter_oa/mainpage/works.dart';
import 'package:flutter_oa/viewpagers/page_host.dart';

import 'customer.dart';
import 'mine.dart';

class MainPage extends StatefulWidget {
  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage>
    with SingleTickerProviderStateMixin {
  var titles = ['客户', '产品', '工作', '分类','我的'];
  var imgs = [
    Icon(Icons.person),
    Icon(Icons.domain),
    Icon(Icons.work),
    Icon(Icons.high_quality),
    Icon(Icons.pan_tool)
  ];
  String title = '客户';
  List<BottomNavigationBarItem> icons = new List();

  int _currentIndex = 0;
  var _controller = PageController(
    initialPage: 0,
  );

  @override
  void dispose() {
    super.dispose();
    _controller.dispose();
  }

  List<BottomNavigationBarItem> setIcons() {
    icons.clear();
    for (var i = 0; i < titles.length; i++) {
      icons.add(BottomNavigationBarItem(
          icon: imgs[i],
          title: Text(
            titles[i],
          )));
    }

    return icons;
  }

//  Color getTabIcon(int curIndex) {
//    if (curIndex == _currentIndex) {
//      return Colors.green;
//    }
//    return Colors.black54;
//  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: PageView(
        controller: _controller,
        children: [Customer(), Product(), Works(),PageHost(), Mine()],
        physics: NeverScrollableScrollPhysics(),
      ),
      bottomNavigationBar: BottomNavigationBar(
          currentIndex: _currentIndex,
          selectedItemColor: Colors.green,
          unselectedItemColor: Colors.black54,
          selectedFontSize: 14,
          unselectedFontSize: 14,
          onTap: (index) {
            title = titles[index];
            _controller.jumpToPage(index);
            setState(() {
              _currentIndex = index;
            });
          },
          type: BottomNavigationBarType.fixed,
          items: setIcons()),
    );
  }
}
